package Test;

import java.util.ArrayList;

public class StudentsTest {
    public static void main(String[] args) {
        //定义一个集合，添加一个学生对象，并进行遍历
        //学生类的属性为：姓名，年龄

        //1.创建集合
        ArrayList<Students> list = new ArrayList<>();

        //2.创建学生对象
        Students s1 = new Students("zhangsan",23);
        Students s2 = new Students("lisi",25);
        Students s3 = new Students("wangwu",22);

        //3.添加对象
        list.add(s1);
        list.add(s2);
        list.add(s3);

        //4.遍历集合
        for (int i = 0; i < list.size(); i++) {
            Students stu = list.get(i);
            System.out.println(stu.getName() + "," + stu.getAge());
        }
    }
}
